//
//  PKPlayListTableViewController.m
//  PianKe
//
//  Created by mingtao on 15/10/6.
//  Copyright (c) 2015年 mingtao. All rights reserved.
//

#import "PKPlayListTableViewController.h"
#import "PKPlayListTableViewCell.h"

#import "PKRadioModelDetailfile.h"

//#import "PKPlayViewController.h"


@interface PKPlayListTableViewController ()

@property(nonatomic,strong)NSMutableArray *NsArray;


@end

@implementation PKPlayListTableViewController

-(NSMutableArray *)NsArray
{
    if (_NsArray == nil) {
        _NsArray = [NSMutableArray arrayWithCapacity:0];
    }
    return _NsArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    
    [self.tableView registerClass:[PKPlayListTableViewCell class] forCellReuseIdentifier:@"pkPlayListTableviewCell"];
      self.tableView.rowHeight = 60;
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return _dataSourceArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    PKPlayListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pkPlayListTableviewCell" forIndexPath:indexPath];
    
    cell.configureModel=self.dataSourceArray[indexPath.row];
    
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //选中
    
   // cell.configureModel.isSelected = NO;
    
    for (int i = 0; i<_dataSourceArray.count; i++) {
        PKRadioModelDetailfile *mode=_dataSourceArray[i];
        
        mode.isSelected = NO;
        
        PKPlayListTableViewCell *cell=(PKPlayListTableViewCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
        cell.leftView.backgroundColor=[UIColor whiteColor];

    }
    
    for (int i = 0; i<_dataSourceArray.count; i++) {
        PKRadioModelDetailfile *models=_dataSourceArray[i];
        
        [self.NsArray addObject:models.tingid];
        
    }
    //设置通知
    
    PKPlayListTableViewCell *cell=(PKPlayListTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    
    cell.leftView.backgroundColor=[UIColor greenColor];
    //通知
    [[NSNotificationCenter defaultCenter]postNotificationName:@"changsha" object:@"pkpalaylist" userInfo:[NSDictionary dictionaryWithObject:indexPath forKey:@"indexpath"]];
    
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"changgelist" object:@"parllist"userInfo:[NSDictionary dictionaryWithObject:self.NsArray forKey:@"Nsarrays"]];
    
    
    PKRadioModelDetailfile *model=_dataSourceArray[indexPath.row];
    
    model.isSelected = YES;
    
//    PKPlayViewController *PlayScrView=[[PKPlayViewController alloc]init];
//    
//    [self.navigationController pushViewController:PlayScrView animated:YES];
    
    _parDetailBlock(indexPath.row);
    
    
   
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //非选中的时候
    PKPlayListTableViewCell *cell=(PKPlayListTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    cell.leftView.backgroundColor=[UIColor whiteColor];
    
    cell.configureModel.isSelected = NO;
//    
 //   PKRadioModelDetailfile *model=_dataSourceArray[indexPath.row];
    
    
   // PKRadioModelDetailfile *model = _dataSourceArray[indexPath.row];
   // model.isSelected=YES;
    
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
